﻿Public Class FrmCovoiturage

    Dim DateChercheEnCours As DateTime

    Private Sub FrmCovoiturage_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        SaveMoisEnCours()

    End Sub

    Private Sub SaveMoisEnCours()

        Dim i As Integer
        Dim NomFic As String

        For i = 1 To 42
            If GroupBoxCalendrier.Controls("LblJour" & i).Text <> "" Then
                NomFic = Rep & "Fic\" & Format(DateChercheEnCours, "yyyyMM") & GroupBoxCalendrier.Controls("LblJour" & i).Text & ".txt"
                If GroupBoxCalendrier.Controls("LblJour" & i).Tag.ToString <> "" And Val(GroupBoxCalendrier.Controls("LblJour" & i).Tag) <> 6 Then
                    FileOpen(1, NomFic, OpenMode.Output)
                    PrintLine(1, GroupBoxCalendrier.Controls("LblJour" & i).Tag)
                    FileClose(1)
                Else
                    If IO.File.Exists(NomFic) Then
                        Kill(NomFic)
                    End If
                End If
            End If
        Next i

    End Sub

    Private Sub FrmCovoiturage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim Tmp As String

        'Repertoir courant de l'application
        Rep = Application.StartupPath()
        If Rep.Substring(1, 1) <> "\" Then Rep = Rep & "\"

        If IO.Directory.Exists(Rep & "Fic") = False Then
            MkDir(Rep & "Fic")
        End If

        ReDim Preserve TbCovoitureur(6)
        Tmp = GetSetting("Covoiturage", "Parametres", "Covoitureur1")
        If Tmp = "" Then
            TbCovoitureur(1) = "Covoitureur 1"
        Else
            TbCovoitureur(1) = Tmp
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Covoitureur2")
        If Tmp = "" Then
            TbCovoitureur(2) = "Covoitureur 2"
        Else
            TbCovoitureur(2) = Tmp
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Covoitureur3")
        If Tmp = "" Then
            TbCovoitureur(3) = ""
        Else
            TbCovoitureur(3) = Tmp
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Covoitureur4")
        If Tmp = "" Then
            TbCovoitureur(4) = ""
        Else
            TbCovoitureur(4) = Tmp
        End If

        ReDim Preserve TbCouleur(6)
        Tmp = GetSetting("Covoiturage", "Parametres", "Couleur1")
        If Tmp = "" Then
            TbCouleur(1) = Color.LightPink
        Else
            TbCouleur(1) = Color.FromArgb(CInt(Tmp))
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Couleur2")
        If Tmp = "" Then
            TbCouleur(2) = Color.LightBlue
        Else
            TbCouleur(2) = Color.FromArgb(CInt(Tmp))
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Couleur3")
        If Tmp = "" Then
            TbCouleur(3) = Color.LightCoral
        Else
            TbCouleur(3) = Color.FromArgb(CInt(Tmp))
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "Couleur4")
        If Tmp = "" Then
            TbCouleur(4) = Color.LightGreen
        Else
            TbCouleur(4) = Color.FromArgb(CInt(Tmp))
        End If

        TbCovoitureur(5) = "Seul"
        TbCovoitureur(6) = "NonDefinie"
        TbCouleur(5) = Color.GhostWhite
        TbCouleur(6) = Color.Moccasin

        Tmp = GetSetting("Covoiturage", "Parametres", "DistanceTrajet")
        If Tmp <> "" Then
            DistanceTrajet = Tmp
        Else
            DistanceTrajet = 0
        End If

        Tmp = GetSetting("Covoiturage", "Parametres", "PrixCarburant")
        If Tmp <> "" Then
            PrixCarburant = Tmp
        Else
            PrixCarburant = 1.41
        End If

        Tmp = GetSetting("Covoiturage", "Parametres", "ConsoVoiture")
        If Tmp <> "" Then
            ConsoVoiture = Tmp
        Else
            ConsoVoiture = 5
        End If

        Tmp = GetSetting("Covoiturage", "Parametres", "CoutTrajet")
        If Tmp <> "" Then
            CoutTrajet = Tmp
        Else
            CoutTrajet = 0
        End If

        Tmp = GetSetting("Covoiturage", "Parametres", "CoKm")
        If Tmp <> "" Then
            CoKm = Tmp
        Else
            CoKm = 110
        End If
        Tmp = GetSetting("Covoiturage", "Parametres", "CoParcour")
        If Tmp <> "" Then
            CoParcour = Tmp
        Else
            CoParcour = 6.82
        End If

        MefDataGridView()

        CreListeCovoitureurs()

        'DateCherche = DateAdd("m", -2, Now)
        DateChercheEnCours = Now
        ChargeSkin()
        ChargeCalendrier(DateChercheEnCours)
        ChargeStats()
        'DataGridView1.Focused = False

    End Sub

    Private Sub ChargeCalendrier(ByVal DateCherche As DateTime)

        Dim PremierJourMois As Integer, NumControl As Integer
        Dim i As Integer, j As Integer
        Dim Nom As String

        LblMois.Text = Format(DateCherche, "MMMM yyyy")
        LblMois.Text = UCase(LblMois.Text.Substring(0, 1)) & LCase(LblMois.Text.Substring(1))
        'LswStats.Columns.Item(1).Text = UCase(Format(DateCherche, "MMMM").Substring(0, 1)) & LCase(Format(DateCherche, "MMMM").Substring(1)) '
        Nom = UCase(Format(DateCherche, "MMMM").Substring(0, 1)) & LCase(Format(DateCherche, "MMMM").Substring(1))
        If Nom.Length > 4 Then
            DataGridView1.Columns(1).Name = "Nb trajets" & vbCrLf & Nom.Substring(0, 4) & "."
        Else
            DataGridView1.Columns(1).Name = "Nb trajets" & vbCrLf & Nom
        End If

        PremierJourMois = Weekday("01/" & Format(DateCherche, "M/yyyy"))
        If PremierJourMois = 1 Then PremierJourMois = 8

        For i = 1 To 42
            GroupBoxCalendrier.Controls("LblJour" & i).Visible = True
            GroupBoxCalendrier.Controls("LblJour" & i).Tag = ""
            GroupBoxCalendrier.Controls("LblJour" & i).Text = ""
            If GroupBoxCalendrier.Controls("LblJour" & i).BackColor <> Color.Teal Then
                GroupBoxCalendrier.Controls("LblJour" & i).BackColor = Color.Moccasin
            End If
        Next
        NumControl = 1
        For i = 1 To PremierJourMois - 2
            GroupBoxCalendrier.Controls("LblJour" & NumControl).Visible = False
            NumControl = NumControl + 1
        Next i
        Dim nbJoursMois As Integer = DateTime.DaysInMonth(DateCherche.Year, DateCherche.Month)
        For i = 1 To nbJoursMois
            If GroupBoxCalendrier.Controls("LblJour" & NumControl).BackColor <> Color.Teal Then
                If Format(Now, "dd/MM/yyyy") = Format(i, "00") & Format(DateCherche, "/MM/yyyy") Then
                    GroupBoxCalendrier.Controls("LblJour" & NumControl).ForeColor = Color.Black
                    GroupBoxCalendrier.Controls("LblJour" & NumControl).Font = New Font(GroupBoxCalendrier.Controls("LblJour" & NumControl).Font, FontStyle.Bold)
                Else
                    GroupBoxCalendrier.Controls("LblJour" & NumControl).ForeColor = Color.Gray
                    GroupBoxCalendrier.Controls("LblJour" & NumControl).Font = New Font(GroupBoxCalendrier.Controls("LblJour" & NumControl).Font, FontStyle.Regular)
                End If
            End If
            GroupBoxCalendrier.Controls("LblJour" & NumControl).Text = Format(i, "00")
            Nom = LitFicJour(Format(DateCherche, "yyyyMM") & Format(i, "00"))
            Select Case Nom
                Case ""
                    If GroupBoxCalendrier.Controls("LblJour" & NumControl).BackColor <> Color.Teal Then
                        GroupBoxCalendrier.Controls("LblJour" & NumControl).BackColor = Color.Moccasin
                        GroupBoxCalendrier.Controls("LblJour" & NumControl).Tag = ""
                    End If
                Case Else
                    For j = 1 To TbCovoitureur.Count - 1
                        If TbCovoitureur(j) = Nom Then
                            GroupBoxCalendrier.Controls("LblJour" & NumControl).BackColor = TbCouleur(j)
                            GroupBoxCalendrier.Controls("LblJour" & NumControl).Tag = j
                        End If
                    Next j
            End Select
            NumControl = NumControl + 1
        Next i
        For i = NumControl To 42
            GroupBoxCalendrier.Controls("LblJour" & i).Visible = False
        Next

    End Sub

    Private Function LitFicJour(ByVal Jour As String) As String

        Dim Ligne As String, NomFic As String

        Ligne = ""
        NomFic = Rep & "Fic\" & Jour & ".txt"
        If IO.File.Exists(NomFic) Then
            FileOpen(1, NomFic, OpenMode.Input)
            Ligne = LineInput(1)
            FileClose(1)
        End If
        If Ligne = "" Then
            Return Ligne
        Else
            Ligne = TbCovoitureur(Ligne)
            Return Ligne
        End If


    End Function

    Private Sub LblJour1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour1.Click

        GereClique(LblJour1)

    End Sub

    Private Sub GereClique(ByVal LabelClique As Label)

        If Val(LabelClique.Tag) < TbCovoitureur.Count - 1 Then
            LabelClique.Tag = Val(LabelClique.Tag) + 1
            While TbCovoitureur(Val(LabelClique.Tag)) = ""
                LabelClique.Tag = Val(LabelClique.Tag) + 1
            End While
        Else
            LabelClique.Tag = 1
        End If
        LabelClique.BackColor = TbCouleur(LabelClique.Tag)
        SaveMoisEnCours()
        ChargeStats()

    End Sub

    Private Sub LblJour2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour2.Click
        GereClique(LblJour2)
    End Sub

    Private Sub LblJour3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour3.Click
        GereClique(LblJour3)
    End Sub

    Private Sub LblJour4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour4.Click
        GereClique(LblJour4)
    End Sub

    Private Sub LblJour5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour5.Click
        GereClique(LblJour5)
    End Sub

    Private Sub LblJour8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour8.Click
        GereClique(LblJour8)
    End Sub

    Private Sub LblJour9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour9.Click
        GereClique(LblJour9)
    End Sub

    Private Sub LblJour10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour10.Click
        GereClique(LblJour10)
    End Sub

    Private Sub LblJour11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour11.Click
        GereClique(LblJour11)
    End Sub

    Private Sub LblJour12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour12.Click
        GereClique(LblJour12)
    End Sub

    Private Sub LblJour15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour15.Click
        GereClique(LblJour15)
    End Sub

    Private Sub LblJour16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour16.Click
        GereClique(LblJour16)
    End Sub

    Private Sub LblJour17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour17.Click
        GereClique(LblJour17)
    End Sub

    Private Sub LblJour18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour18.Click
        GereClique(LblJour18)
    End Sub

    Private Sub LblJour19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour19.Click
        GereClique(LblJour19)
    End Sub

    Private Sub LblJour22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour22.Click
        GereClique(LblJour22)
    End Sub

    Private Sub LblJour23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour23.Click
        GereClique(LblJour23)
    End Sub

    Private Sub LblJour24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour24.Click
        GereClique(LblJour24)
    End Sub

    Private Sub LblJour25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour25.Click
        GereClique(LblJour25)
    End Sub

    Private Sub LblJour26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour26.Click
        GereClique(LblJour26)
    End Sub

    Private Sub LblJour29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour29.Click
        GereClique(LblJour29)
    End Sub

    Private Sub LblJour30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour30.Click
        GereClique(LblJour30)
    End Sub

    Private Sub LblJour31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour31.Click
        GereClique(LblJour31)
    End Sub

    Private Sub LblJour32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour32.Click
        GereClique(LblJour32)
    End Sub

    Private Sub LblJour33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour33.Click
        GereClique(LblJour33)
    End Sub

    Private Sub LblJour36_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour36.Click
        GereClique(LblJour36)
    End Sub

    Private Sub LblJour37_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour37.Click
        GereClique(LblJour37)
    End Sub

    Private Sub LblJour38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour38.Click
        GereClique(LblJour38)
    End Sub

    Private Sub LblJour39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
        GereClique(LblJour39)
    End Sub

    Private Sub LblJour40_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblJour40.Click
        GereClique(LblJour40)
    End Sub

    Private Sub CmdPrecedent_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdPrecedent.Click

        SaveMoisEnCours()
        DateChercheEnCours = DateAdd("m", -1, DateChercheEnCours)
        ChargeSkin()
        ChargeCalendrier(DateChercheEnCours)
        ChargeStats()

    End Sub

    Private Sub CmdSuivant_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSuivant.Click

        SaveMoisEnCours()
        DateChercheEnCours = DateAdd("m", 1, DateChercheEnCours)
        ChargeSkin()
        ChargeCalendrier(DateChercheEnCours)
        ChargeStats()

    End Sub

    Private Sub ChargeStats()

        Dim NomFic As String, Ligne As String
        Dim TbStats() As Integer, TbStatsMois() As Integer, TotalTrajet As Integer, NbSeul As Integer
        Dim NbCovoitureur As Integer, TotalMois As Integer, Total As Integer
        Dim TotalDepenses As Integer, TotalEconomies As Integer

        ReDim TbStats(TbCovoitureur.Count - 1)
        ReDim TbStatsMois(TbCovoitureur.Count - 1)
        NbCovoitureur = 0
        NbSeul = 0
        TotalDepenses = 0
        TotalEconomies = 0
        NomFic = Dir(Rep & "Fic\*.txt", FileAttribute.Normal)
        While NomFic <> ""
            FileOpen(1, Rep & "Fic\" & NomFic, OpenMode.Input)
            Ligne = LineInput(1)
            FileClose(1)
            If Ligne <> "" And Val(Ligne) < 4 Then
                TbStats(Ligne) = TbStats(Ligne) + 1
                TotalTrajet = TotalTrajet + 1
                If NomFic.Substring(0, 6) = Format(DateChercheEnCours, "yyyyMM") Then
                    TbStatsMois(Ligne) = TbStatsMois(Ligne) + 1
                End If
            Else
                If Val(Ligne) = 5 Then
                    'Seul
                    NbSeul = NbSeul + 1
                End If
            End If
            NomFic = Dir()
        End While

        TotalMois = 0
        Total = 0
        DataGridView1.Rows.Clear()
        For i = 1 To 4
            If TbCovoitureur(i) <> "" Then
                NbCovoitureur = NbCovoitureur + 1
                DataGridView1.Rows.Add()
                DataGridView1.Rows(i - 1).DefaultCellStyle.BackColor = TbCouleur(i)
                DataGridView1.Rows(i - 1).Cells(0).Value = TbCovoitureur(i)
                DataGridView1.Rows(i - 1).Cells(1).Value = TbStatsMois(i)
                DataGridView1.Rows(i - 1).Cells(2).Value = TbStats(i)
                If i = 1 Then
                    DataGridView1.Rows(i - 1).Cells(3).Value = NbSeul
                    DataGridView1.Rows(i - 1).Cells(4).Value = FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoutTrajet, 2) & " ( " & TbStats(i) + TbStats(5) + NbSeul & ")"
                    DataGridView1.Rows(i - 1).Cells(5).Value = FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoParcour, 2) & " ( " & TbStats(i) + TbStats(5) + NbSeul & ")"
                    TotalDepenses = TotalDepenses + (TbStats(i) + TbStats(5) + NbSeul)
                Else
                    DataGridView1.Rows(i - 1).Cells(3).Value = "-"
                    DataGridView1.Rows(i - 1).Cells(4).Value = FormatNumber((TbStats(i) + TbStats(5)) * CoutTrajet, 2) & " ( " & TbStats(i) + TbStats(5) & ")"
                    DataGridView1.Rows(i - 1).Cells(5).Value = FormatNumber((TbStats(i) + TbStats(5)) * CoParcour, 2) & " ( " & TbStats(i) + TbStats(5) & ")"
                    TotalDepenses = TotalDepenses + (TbStats(i) + TbStats(5))
                End If
                DataGridView1.Rows(i - 1).Cells(6).Value = FormatNumber((TotalTrajet - TbStats(i)) * CoutTrajet, 2) & " (" & TotalTrajet - TbStats(i) & ")"
                DataGridView1.Rows(i - 1).Cells(7).Value = FormatNumber((TotalTrajet - TbStats(i)) * CoParcour, 2) & " (" & TotalTrajet - TbStats(i) & ")"
                TotalMois = TotalMois + TbStatsMois(i)
                Total = Total + TbStats(i)
                TotalEconomies = TotalEconomies + (TotalTrajet - TbStats(i))
                'Else
                'DataGridView1.Rows(i - 1).DefaultCellStyle.BackColor = Color.White
                'DataGridView1.Rows(i - 1).Cells(0).Value = ""
                'DataGridView1.Rows(i - 1).Cells(1).Value = ""
                'DataGridView1.Rows(i - 1).Cells(2).Value = ""
                'DataGridView1.Rows(i - 1).Cells(3).Value = ""
                'DataGridView1.Rows(i - 1).Cells(4).Value = ""
                'DataGridView1.Rows(i - 1).Cells(5).Value = ""
                'DataGridView1.Rows(i - 1).Cells(6).Value = ""
                'DataGridView1.Rows(i - 1).Cells(7).Value = ""
            End If
        Next
        DataGridView1.Rows.Add()
        DataGridView1.Rows(NbCovoitureur).Cells(0).Value = "Total"
        DataGridView1.Rows(NbCovoitureur).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Bold)
        DataGridView1.Rows(NbCovoitureur).Cells(1).Value = TotalMois
        DataGridView1.Rows(NbCovoitureur).Cells(2).Value = Total
        DataGridView1.Rows(NbCovoitureur).Cells(3).Value = NbSeul
        DataGridView1.Rows(NbCovoitureur).Cells(4).Value = FormatNumber(TotalDepenses * CoutTrajet, 2)
        DataGridView1.Rows(NbCovoitureur).Cells(5).Value = FormatNumber(TotalDepenses * CoParcour, 2)
        DataGridView1.Rows(NbCovoitureur).Cells(6).Value = FormatNumber(TotalEconomies * CoutTrajet, 2)
        DataGridView1.Rows(NbCovoitureur).Cells(7).Value = FormatNumber(TotalEconomies * CoParcour, 2)
        DataGridView1.Rows(NbCovoitureur).Selected = True

        DataGridView1.AutoSize() = True
        Me.Height = DataGridView1.Top + DataGridView1.Height + 25
        'DataGridView1.Height = DataGridView1.Rows(NbCovoitureur).Height
    End Sub

    Private Sub CmdFermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Me.Close()

    End Sub

    Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click

        Me.Close()

    End Sub

    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click

        If FrmOptions.ShowDialog() = Windows.Forms.DialogResult.OK Then
            CreListeCovoitureurs()
            ChargeCalendrier(DateChercheEnCours)
            ChargeStats()
        End If

    End Sub

    Private Sub AProposeDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AProposeDeToolStripMenuItem.Click

        FrmAProposeDe.ShowDialog()

    End Sub

    Private Sub CreListeCovoitureurs()

        Dim i As Integer

        For i = 1 To 4
            If TbCovoitureur.Count > i Then
                If TbCovoitureur(i) = "" Then
                    Controls("LblCovoiturreur" & i).Visible = False
                    Controls("LblCouleur" & i).Visible = False
                Else
                    Controls("LblCovoiturreur" & i).Text = TbCovoitureur(i)
                    Controls("LblCouleur" & i).BackColor = TbCouleur(i)
                    Controls("LblCovoiturreur" & i).Visible = True
                    Controls("LblCouleur" & i).Visible = True
                End If
                'GroupBox1.Height = GroupBox1.Controls("LblCouleur" & i).Top + GroupBox1.Controls("LblCouleur" & i).Height + 20
            Else
                Controls("LblCovoiturreur" & i).Visible = False
                Controls("LblCouleur" & i).Visible = False
            End If
        Next

    End Sub

    Private Sub LswStats_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub CreHtml()

        Dim i As Integer, Pos As Integer
        Dim s As String, Ligne As String
        Dim TbStats() As Single, TbListeDate() As String, TbListeNom() As Integer
        Dim NbSeul As Integer, TotalTrajet As String, ListeMois As String

        ReDim TbStats(TbCovoitureur.Count - 1)
        ReDim TbListeDate(0)
        ReDim TbListeNom(0)
        TbListeDate(0) = ""
        ListeMois = ""
        NbSeul = 0
        TotalTrajet = 0

        Dim ListeFic As String() = IO.Directory.GetFiles(Rep & "Fic\")

        Array.Sort(ListeFic)
        For i = 0 To ListeFic.Count - 1
            Pos = ListeFic(i).LastIndexOf("\")
            s = ListeFic(i).Substring(Pos + 1)
            s = s.Substring(0, s.Length - 4)
            s = s.Substring(6, 2) & "/" & s.Substring(4, 2) & "/" & s.Substring(0, 4)

            FileOpen(2, ListeFic(i), OpenMode.Input)
            Ligne = LineInput(2)
            FileClose(2)

            ReDim Preserve TbListeDate(i)
            TbListeDate(i) = s
            ReDim Preserve TbListeNom(i)
            TbListeNom(i) = Val(Ligne)

            If Ligne <> "" And Val(Ligne) < 4 Then
                TbStats(Ligne) = TbStats(Ligne) + 1
                TotalTrajet = TotalTrajet + 1
            Else
                If Val(Ligne) = 5 Then
                    'Seul
                    NbSeul = NbSeul + 1
                End If
            End If

        Next

        FileOpen(1, Rep & "Compte-voiturage.html", OpenMode.Output)
        PrintLine(1, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>")
        PrintLine(1, "<html>")
        PrintLine(1, "<head>")
        PrintLine(1, "    <meta http-equiv='Content-Type' content='text/HTML; charset=ISO-8859-1' />")
        PrintLine(1, "    <link rel='stylesheet' media='screen,projection' type='text/css' href='css/main.css' />")
        PrintLine(1, "    <!--[if lte IE 6]><link rel='stylesheet' type='text/css' href='css/main-msie.css' /><![endif]-->")
        PrintLine(1, "    <link rel='stylesheet' media='screen,projection' type='text/css' href='css/scheme.css' />")
        PrintLine(1, "    <link rel='stylesheet' media='print' type='text/css' href='css/print.css' />")
        PrintLine(1, "<title>Compte-voiturage</title>")
        PrintLine(1, "</head>")
        PrintLine(1, "<body>")
        PrintLine(1, "<div id='main'>")
        PrintLine(1, "    <!-- Header -->")
        PrintLine(1, "    <div id='header'>")
        PrintLine(1, "        <!-- Logo -->")
        PrintLine(1, "	<h1 id='logo'><div><a href='./' title='Compte-Voiturage'>Compte-<span>voiturage</span></a></div></table></h1>")
        PrintLine(1, "        <hr class='noscreen' />")
        PrintLine(1, "        <!-- RSS feeds -->")
        PrintLine(1, "        <div id='rss'>")
        PrintLine(1, "            <img src='./design/covoitureur.png'>")
        PrintLine(1, "        </div> <!-- /rss -->")
        PrintLine(1, "        <hr class='noscreen' />")
        PrintLine(1, "    </div> <!-- /header -->")
        PrintLine(1, "    <!-- Body -->")
        PrintLine(1, "    <div id='cols' class='box'>")
        PrintLine(1, "        <!-- Content -->")
        PrintLine(1, "        <div id='content'>")
        PrintLine(1, "            <h1 id='title'><img src='./design/logo_p2.png'> Statistiques globales</h1>")
        PrintLine(1, "	    <div id='perex' class='box'>")
        PrintLine(1, "Du " & TbListeDate(0) & " au " & TbListeDate(TbListeDate.Length - 1))
        PrintLine(1, "		    <center>")

        PrintLine(1, "<table id='stats'>")
        PrintLine(1, "<tr><th rowspan=2 > </th><th colspan=2  >Trajets</th><th colspan=3 >Dépense</th><th colspan=3 >Economie</th></tr>")
        PrintLine(1, "<tr><th>Total</th><th>Seul</th><th>Trajets</th><th>Euros</th><th>Kg Co2</th><th>Trajets</th><th>Euros</th><th>Kg Co2</th></tr>")
        For i = 1 To 4
            If TbCovoitureur(i) <> "" Then
                PrintLine(1, "<tr>")

                PrintLine(1, "<td bgcolor='" & ColorTranslator.ToHtml(TbCouleur(i)) & "'>" & TbCovoitureur(i) & "</td>")
                PrintLine(1, "<td><center>" & TbStats(i) & "</td>")
                If i = 1 Then
                    PrintLine(1, "<td><center>" & NbSeul & "</td>")
                    PrintLine(1, "<td><center>" & TbStats(i) + TbStats(5) + NbSeul & "</td>")
                    PrintLine(1, "<td><center>" & FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoutTrajet, 2) & "</td>")
                    PrintLine(1, "<td><center>" & FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoParcour, 2) & "</td>")
                Else
                    PrintLine(1, "<td><center> - </td>")
                    PrintLine(1, "<td><center>" & TbStats(i) + TbStats(5) & "</td>")
                    PrintLine(1, "<td><center>" & FormatNumber((TbStats(i) + TbStats(5)) * CoutTrajet, 2) & "</td>")
                    PrintLine(1, "<td><center>" & FormatNumber((TbStats(i) + TbStats(5)) * CoParcour, 2) & "</td>")
                End If

                PrintLine(1, "<td><center>" & TotalTrajet - TbStats(i) & "</td>")
                PrintLine(1, "<td><center>" & FormatNumber((TotalTrajet - TbStats(i)) * CoutTrajet, 2) & "</td>")
                PrintLine(1, "<td><center>" & FormatNumber((TotalTrajet - TbStats(i)) * CoParcour, 2) & "</td>")
                PrintLine(1, "</tr>")
            End If
        Next
        PrintLine(1, "</table>")

        PrintLine(1, "	    </center>")
        PrintLine(1, "            </div> <!-- /perex -->")
        PrintLine(1, "	    <br>")
        PrintLine(1, "            <h1 id='title'><img src='./design/logo_p2.png'> Liste</h1>")
        PrintLine(1, "	    <div id='perex' class='box'>")
        PrintLine(1, "		    <center>")

        '==========================================================
        If TbListeDate(0).Length = 10 Then

            Dim PremierJourMois As Integer, NumControl As Integer
            Dim FonCouleur As String
            Dim nbJoursMois As Integer
            Dim MoisEnCours As String

            MoisEnCours = "01" & TbListeDate(0).Substring(2)
            Do

                PrintLine(1, "<p id='" & Format(CDate(MoisEnCours), "MMMMyyyy") & "'>")
                ListeMois = ListeMois & "<li><a href='#" & Format(CDate(MoisEnCours), "MMMMyyyy") & "'>" & Format(CDate(MoisEnCours), "MMMM yyyy") & "</a></li>"

                PrintLine(1, "<table id='calendar'>")
                PrintLine(1, "<caption>" & Format(CDate(MoisEnCours), "MMMM yyyy") & "</caption>")
                PrintLine(1, "<th>Lun</th><th>Mar</th><th>Mer</th><th>Jeu</th><th>Ven</th><th>Sam</th><th>Dim</th>")
                PremierJourMois = Weekday("01" & MoisEnCours.Substring(2))
                If PremierJourMois = 1 Then PremierJourMois = 8

                NumControl = 1
                PrintLine(1, "<tr>")
                For i = 1 To PremierJourMois - 2
                    PrintLine(1, "<td></td>")
                    NumControl = NumControl + 1
                Next i

                nbJoursMois = DateTime.DaysInMonth(MoisEnCours.Substring(6), MoisEnCours.Substring(3, 2))
                For i = 1 To nbJoursMois
                    NumControl = NumControl + 1
                    FonCouleur = ""
                    For j = 0 To TbListeDate.Length - 1
                        If Format(i, "00") & MoisEnCours.Substring(2) = TbListeDate(j) Then
                            FonCouleur = " bgcolor='" & ColorTranslator.ToHtml(TbCouleur(TbListeNom(j))) & "'"
                            Exit For
                        End If
                    Next

                    PrintLine(1, "<td " & FonCouleur & "><center>" & i & "</td>")
                    If (NumControl - 1) Mod 7 = 0 Then
                        PrintLine(1, "</tr><tr>")
                    End If
                Next i
                PrintLine(1, "</tr>")
                PrintLine(1, "</table>")

                MoisEnCours = DateAdd("m", 1, MoisEnCours)
                If DateDiff("m", "01" & TbListeDate(TbListeDate.Count - 1).Substring(2), MoisEnCours) >= 1 Then
                    Exit Do
                End If

            Loop
        End If

        PrintLine(1, "	</center>")
        PrintLine(1, "            </div> <!-- /perex -->")
        PrintLine(1, "	    <!-- 2 columns -->")
        PrintLine(1, "            <div class='cols5050 box'>")
        PrintLine(1, "                <!-- Left column -->")
        PrintLine(1, "                <div class='col'>")
        PrintLine(1, "                </div> <!-- /col -->")
        PrintLine(1, "                <!-- Right column -->")
        PrintLine(1, "                <div class='col f-right'>")
        PrintLine(1, "                </div> <!-- /col -->")
        PrintLine(1, "            </div> <!-- /cols5050 -->")
        PrintLine(1, "            <!-- Buttons -->")
        PrintLine(1, "            <div class='box'>")
        PrintLine(1, "            </div> <!-- /box -->")
        PrintLine(1, "        <hr class='noscreen' />")
        PrintLine(1, "        </div> <!-- /content -->")
        PrintLine(1, "        <!-- Sidebar -->")
        PrintLine(1, "        <div id='aside'>")
        PrintLine(1, "            <!-- About -->")
        PrintLine(1, "            <div id='about' class='box'>")
        PrintLine(1, "                <img src='design/caricatu.jpg' alt='' class='f-left' />")
        'PrintLine(1, "                <strong class='high'>Par Manu...</strong><br />")
        PrintLine(1, "            </div> <!-- /about -->")
        PrintLine(1, "            <!-- Liste -->")
        PrintLine(1, "            <h4>Mois</h4>")
        PrintLine(1, "            <ul class='nav'>")
        PrintLine(1, ListeMois)
        PrintLine(1, "            </ul>")
        PrintLine(1, "        <hr class='noscreen' />")
        PrintLine(1, "        </div> <!-- /aside -->")
        PrintLine(1, "     </div> <!-- /cols -->")
        PrintLine(1, "    <!-- Footer -->")
        PrintLine(1, "    <div id='footer' class='box'>")
        PrintLine(1, "        <hr class='noscreen' />")
        PrintLine(1, "        <p>&copy;&nbsp;2012 <a href='#'>Compt-voiturage</a></p>")
        PrintLine(1, "    </div> <!-- /footer -->")
        PrintLine(1, "</div> <!-- /main -->")

        PrintLine(1, "</body>")
        PrintLine(1, "</html>")
        FileClose(1)

    End Sub

    Private Sub ExporterEnHtmlToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExporterEnHtmlToolStripMenuItem.Click

        CreHtml()
        'System.Diagnostics.Process.Start(Rep & "Compte-voiturage.html")
        FrmWeb.ShowDialog()

    End Sub

    Private Sub AperçuAvantImpressionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AperçuAvantImpressionToolStripMenuItem.Click

        Dim PrintPreviewDialog1 = New PrintPreviewDialog

        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.Width = 600
        PrintPreviewDialog1.Height = 800
        'PrintPreviewDialog1.Created = True
        PrintPreviewDialog1.Show()

    End Sub

    Private Sub PrintDocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.EndPrint

        '        MsgBox("La liste a bien été imprimée")

    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim printFont As Font, printFonttitre As Font
        Dim Hauteur As Integer

        printFont = New Font("Arial", 10)
        printFonttitre = New Font("Arial", 10, FontStyle.Bold)

        Hauteur = 10
        e.Graphics.DrawImage(PictureBox1.Image, 10, Hauteur)
        e.Graphics.DrawString("Compte-Voiturage", New Font("Arial", 35, FontStyle.Regular), Brushes.Black, 10 + PictureBox1.Width, Hauteur)


        Dim i As Integer, Pos As Integer
        Dim s As String, Ligne As String
        Dim TbStats() As Single, TbListeDate() As String, TbListeNom() As Integer
        Dim NbSeul As Integer, TotalTrajet As String, ListeMois As String

        ReDim TbStats(TbCovoitureur.Count - 1)
        ReDim TbListeDate(0)
        ReDim TbListeNom(0)
        TbListeDate(0) = ""
        ListeMois = ""
        NbSeul = 0
        TotalTrajet = 0

        Dim ListeFic As String() = IO.Directory.GetFiles(Rep & "Fic\")

        Array.Sort(ListeFic)
        For i = 0 To ListeFic.Count - 1
            Pos = ListeFic(i).LastIndexOf("\")
            s = ListeFic(i).Substring(Pos + 1)
            s = s.Substring(0, s.Length - 4)
            s = s.Substring(6, 2) & "/" & s.Substring(4, 2) & "/" & s.Substring(0, 4)

            FileOpen(2, ListeFic(i), OpenMode.Input)
            Ligne = LineInput(2)
            FileClose(2)

            ReDim Preserve TbListeDate(i)
            TbListeDate(i) = s
            ReDim Preserve TbListeNom(i)
            TbListeNom(i) = Val(Ligne)

            If Ligne <> "" And Val(Ligne) < 4 Then
                TbStats(Ligne) = TbStats(Ligne) + 1
                TotalTrajet = TotalTrajet + 1
            Else
                If Val(Ligne) = 5 Then
                    'Seul
                    NbSeul = NbSeul + 1
                End If
            End If

        Next

        Hauteur = Hauteur + PictureBox1.Height + 20
        e.Graphics.DrawString("Du " & TbListeDate(0) & " au " & TbListeDate(TbListeDate.Length - 1), printFont, Brushes.Black, 20, Hauteur + 10)
        Hauteur = Hauteur + 40

        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(110, Hauteur, 150, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(110, Hauteur, 150, 30))
        e.Graphics.DrawString("Trajets", printFonttitre, Brushes.Black, 165, Hauteur + 10)

        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(260, Hauteur, 225, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(260, Hauteur, 225, 30))
        e.Graphics.DrawString("Dépenses", printFonttitre, Brushes.Black, 340, Hauteur + 10)

        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(485, Hauteur, 225, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(485, Hauteur, 225, 30))
        e.Graphics.DrawString("Economies", printFonttitre, Brushes.Black, 570, Hauteur + 10)

        Hauteur = Hauteur + 30
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(110, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(110, Hauteur, 75, 30))
        e.Graphics.DrawString("Total", printFonttitre, Brushes.Black, 125, Hauteur + 10)
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(185, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(185, Hauteur, 75, 30))
        e.Graphics.DrawString("Seul", printFonttitre, Brushes.Black, 210, Hauteur + 10)

        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(260, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(260, Hauteur, 75, 30))
        e.Graphics.DrawString("Trajets", printFonttitre, Brushes.Black, 270, Hauteur + 10)
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(335, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(335, Hauteur, 75, 30))
        e.Graphics.DrawString("Euros", printFonttitre, Brushes.Black, 345, Hauteur + 10)
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(410, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(410, Hauteur, 75, 30))
        e.Graphics.DrawString("Kg CO2", printFonttitre, Brushes.Black, 420, Hauteur + 10)

        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(485, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(485, Hauteur, 75, 30))
        e.Graphics.DrawString("Trajets", printFonttitre, Brushes.Black, 495, Hauteur + 10)
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(560, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(560, Hauteur, 75, 30))
        e.Graphics.DrawString("Euros", printFonttitre, Brushes.Black, 570, Hauteur + 10)
        e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(635, Hauteur, 75, 30))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(635, Hauteur, 75, 30))
        e.Graphics.DrawString("Kg CO2", printFonttitre, Brushes.Black, 645, Hauteur + 10)

        Hauteur = Hauteur + 30

        For i = 1 To 4
            If TbCovoitureur(i) <> "" Then
                e.Graphics.FillRectangle(New SolidBrush(TbCouleur(i)), New Rectangle(10, Hauteur, 100, 30))
                If TbCovoitureur(i).Length < 11 Then
                    e.Graphics.DrawString(TbCovoitureur(i), printFont, Brushes.Black, 20, Hauteur + 10)
                Else
                    e.Graphics.DrawString(TbCovoitureur(i).Substring(0, 10), printFont, Brushes.Black, 20, Hauteur + 10)
                End If
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(10, Hauteur, 100, 30))


                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(110, Hauteur, 75, 30))
                e.Graphics.DrawString(TbStats(i), printFont, Brushes.Black, 140, Hauteur + 10)

                If i = 1 Then
                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(185, Hauteur, 75, 30))
                    e.Graphics.DrawString(NbSeul, printFont, Brushes.Black, 215, Hauteur + 10)

                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(260, Hauteur, 75, 30))
                    e.Graphics.DrawString(TbStats(i) + TbStats(5) + NbSeul, printFont, Brushes.Black, 290, Hauteur + 10)

                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(335, Hauteur, 75, 30))
                    e.Graphics.DrawString(FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoutTrajet, 2), printFont, Brushes.Black, 350, Hauteur + 10)
                Else
                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(185, Hauteur, 75, 30))
                    e.Graphics.DrawString("-", printFont, Brushes.Black, 215, Hauteur + 10)

                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(260, Hauteur, 75, 30))
                    e.Graphics.DrawString(TbStats(i) + TbStats(5), printFont, Brushes.Black, 290, Hauteur + 10)

                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(335, Hauteur, 75, 30))
                    e.Graphics.DrawString(FormatNumber((TbStats(i) + TbStats(5)) * CoutTrajet, 2), printFont, Brushes.Black, 350, Hauteur + 10)
                End If

                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(410, Hauteur, 75, 30))
                e.Graphics.DrawString(FormatNumber((TbStats(i) + TbStats(5) + NbSeul) * CoParcour, 2), printFont, Brushes.Black, 425, Hauteur + 10)

                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(485, Hauteur, 75, 30))
                e.Graphics.DrawString(TotalTrajet - TbStats(i), printFont, Brushes.Black, 515, Hauteur + 10)

                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(560, Hauteur, 75, 30))
                e.Graphics.DrawString(FormatNumber((TotalTrajet - TbStats(i)) * CoutTrajet, 2), printFont, Brushes.Black, 575, Hauteur + 10)

                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(635, Hauteur, 75, 30))
                e.Graphics.DrawString(FormatNumber((TotalTrajet - TbStats(i)) * CoParcour, 2), printFont, Brushes.Black, 650, Hauteur + 10)

                Hauteur = Hauteur + 30
            End If
        Next
        Hauteur = Hauteur + 10
        e.Graphics.DrawImage(PictureBox2.Image, 10, Hauteur)
        e.Graphics.DrawString("Mois", New Font("Arial", 35, FontStyle.Regular), Brushes.Black, 20 + PictureBox2.Width, Hauteur + 15)
        Hauteur = Hauteur + PictureBox2.Height + 20

        '==========================================================
        If TbListeDate(0).Length = 10 Then

            Dim PremierJourMois As Integer, NumControl As Integer
            Dim FonCouleur As String
            Dim nbJoursMois As Integer
            Dim MoisEnCours As String
            Dim Largeur As Integer


            MoisEnCours = "01" & TbListeDate(0).Substring(2)
            Do
                Largeur = 200
                e.Graphics.DrawString(Format(CDate(MoisEnCours), "MMMM yyyy"), printFont, Brushes.Black, Largeur + 140, Hauteur + 10)
                Hauteur = Hauteur + 30

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur, Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur, Hauteur, 50, 30))
                e.Graphics.DrawString("Lun", printFonttitre, Brushes.Black, Largeur + 10, Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + 50, Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + 50, Hauteur, 50, 30))
                e.Graphics.DrawString("Mar", printFonttitre, Brushes.Black, Largeur + 50 + 10, Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + (50 * 2), Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + (50 * 2), Hauteur, 50, 30))
                e.Graphics.DrawString("Mer", printFonttitre, Brushes.Black, Largeur + 10 + (50 * 2), Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + (50 * 3), Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + (50 * 3), Hauteur, 50, 30))
                e.Graphics.DrawString("Jeu", printFonttitre, Brushes.Black, Largeur + 10 + (50 * 3), Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + (50 * 4), Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + (50 * 4), Hauteur, 50, 30))
                e.Graphics.DrawString("Ven", printFonttitre, Brushes.Black, Largeur + 10 + (50 * 4), Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + (50 * 5), Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + (50 * 5), Hauteur, 50, 30))
                e.Graphics.DrawString("Sam", printFonttitre, Brushes.Black, Largeur + 10 + (50 * 5), Hauteur + 10)

                e.Graphics.FillRectangle(Brushes.LightGray, New Rectangle(Largeur + (50 * 6), Hauteur, 50, 30))
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur + (50 * 6), Hauteur, 50, 30))
                e.Graphics.DrawString("Dim", printFonttitre, Brushes.Black, Largeur + 10 + (50 * 6), Hauteur + 10)

                PremierJourMois = Weekday("01" & MoisEnCours.Substring(2))
                If PremierJourMois = 1 Then PremierJourMois = 8

                NumControl = 1
                Hauteur = Hauteur + 30

                For i = 1 To PremierJourMois - 2
                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur, Hauteur, 50, 30))
                    'PrintLine(1, "<td></td>")
                    NumControl = NumControl + 1
                    Largeur = Largeur + 50
                Next i

                nbJoursMois = DateTime.DaysInMonth(MoisEnCours.Substring(6), MoisEnCours.Substring(3, 2))
                For i = 1 To nbJoursMois
                    NumControl = NumControl + 1
                    FonCouleur = ""
                    For j = 0 To TbListeDate.Length - 1
                        If Format(i, "00") & MoisEnCours.Substring(2) = TbListeDate(j) Then
                            FonCouleur = " bgcolor='" & ColorTranslator.ToHtml(TbCouleur(TbListeNom(j))) & "'"
                            e.Graphics.FillRectangle(New SolidBrush(TbCouleur(TbListeNom(j))), New Rectangle(Largeur, Hauteur, 50, 30))

                            Exit For
                        End If
                    Next

                    'PrintLine(1, "<td " & FonCouleur & "><center>" & i & "</td>")
                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Largeur, Hauteur, 50, 30))
                    e.Graphics.DrawString(i, printFont, Brushes.Black, Largeur + 20, Hauteur + 10)
                    Largeur = Largeur + 50
                    If (NumControl - 1) Mod 7 = 0 Then
                        'PrintLine(1, "</tr><tr>")
                        Hauteur = Hauteur + 30
                        Largeur = 200
                    End If
                Next i
                'PrintLine(1, "</tr>")
                'PrintLine(1, "</table>")

                MoisEnCours = DateAdd("m", 1, MoisEnCours)
                If DateDiff("m", "01" & TbListeDate(TbListeDate.Count - 1).Substring(2), MoisEnCours) >= 1 Then
                    Exit Do
                End If
                Hauteur = Hauteur + 40
            Loop
        End If


    End Sub

    Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ImprimerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripMenuItem.Click

        PrintDocument1.Print()

    End Sub

    Private Sub AideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AideToolStripMenuItem.Click

        Help.ShowHelp(Me, "Compte-Voiturage.chm")

    End Sub

    Private Sub MefDataGridView()

        DataGridView1.ColumnCount = 8
        'DataGridView1.RowCount = 4

        With DataGridView1
            .Name = "MyDataGridView"
            '.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
            .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
            .CellBorderStyle = DataGridViewCellBorderStyle.Single
            .GridColor = Color.Black
            .RowHeadersVisible = False


            'On donne le nom des colonnes
            .Columns(0).Name = ""
            .Columns(0).Width = 90
            .Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
            .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
            .Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(0).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Bold)

            .Columns(1).Name = "Nb trajets" & vbCrLf & "Mois"
            .Columns(1).Width = 56
            .Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(1).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns(2).Name = "Nb trajets" & vbCrLf & "Total"
            .Columns(2).Width = 56
            .Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(2).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns(3).Name = "Nb trajets" & vbCrLf & "Seul"
            .Columns(3).Width = 55
            .Columns(3).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(3).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(3).DefaultCellStyle.WrapMode = DataGridViewTriState.True

            .Columns(4).Name = "Dépense" & vbCr & "€"
            .Columns(4).Width = 75
            .Columns(4).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(4).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns(5).Name = "Dépense" & vbCrLf & "CO2"
            .Columns(5).Width = 75
            .Columns(5).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(5).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns(6).Name = "Economies" & vbCr & "€"
            .Columns(6).Width = 75
            .Columns(6).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(6).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns(7).Name = "Economies" & vbCr & "CO2"
            .Columns(7).Width = 75
            .Columns(7).SortMode = DataGridViewColumnSortMode.NotSortable
            '.Columns(7).DefaultCellStyle.Font = New Font(Me.DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
            .Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
            'Empêche les modifications de lignes, colonnes, l'ajout, la suppression
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False

            '.Dock = DockStyle.Fill

            'Une ligne sur 2 en bleue
            '.RowsDefaultCellStyle.BackColor = Color.White
            '.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue

            'Empeche la saisie dans les cellules (en faite, le permet par programmation)
            .EditMode = DataGridViewEditMode.EditProgrammatically

            .RowHeadersVisible = False 'pas de première colonne d'en tête
            .EnableHeadersVisualStyles = False

        End With

        'Gestion des en-têtes de colonne
        With DataGridView1.ColumnHeadersDefaultCellStyle
            .BackColor = Color.LightSteelBlue
            .ForeColor = Color.Navy
            .Font = New Font(DataGridView1.Font, FontStyle.Bold)
        End With

    End Sub

    Private Sub LswStats_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        FrmOptions.ShowDialog()
    End Sub

    Private Sub ChargeSkin()

        Select Case DateChercheEnCours.Month
            Case 3, 4, 5
                LblMois.Image = LblPrintemps.Image
                LblMois.ForeColor = Color.Black
                PctSaison1.Image = PctPrintemps1.Image
                PctSaison2.Image = PctPrintemps2.Image
            Case 6, 7, 8
                LblMois.Image = LblEte.Image
                LblMois.ForeColor = Color.Black
                PctSaison1.Image = PctEte1.Image
                PctSaison2.Image = PctEte2.Image
            Case 9, 10, 11
                LblMois.Image = LblAutomne.Image
                LblMois.ForeColor = Color.White
                PctSaison1.Image = PctAutomne1.Image
                PctSaison2.Image = PctAutomne2.Image
            Case 12, 1, 2
                LblMois.Image = LblHiver.Image
                LblMois.ForeColor = Color.White
                PctSaison1.Image = PctHiver1.Image
                PctSaison2.Image = PctHiver2.Image
        End Select

    End Sub

    Private Sub VérifierLesMisesÀJourToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VérifierLesMisesÀJourToolStripMenuItem.Click

        Dim Ligne As String, VersionEnLigne As String
        Dim Pos As Integer
        Dim REMOTE_URL As String = "http://code.google.com/p/compte-voiturage/wiki/Version" ' adresse de la page ou du fichier à récuperer 
        Dim F As Integer = FreeFile()
        Dim WEB_CLIENT As New System.Net.WebClient() 'Création du controle client 
        Dim DNL_FILE As String = Rep & "Version.html"  'Adresse de reception 

        Try
            WEB_CLIENT.DownloadFile(REMOTE_URL, DNL_FILE) 'Téléchargement 
        Catch ex As Exception ' S'il y a une erreur alors 
            MsgBox("Erreur lors de la récupération de la version actuelle de Compte-voiturage : " & vbCrLf & "'" & ex.Message & "'", MsgBoxStyle.Exclamation) 'affichier l'erreur dans une Message Box 
            Exit Sub
        End Try
        VersionEnLigne = ""
        FileOpen(1, Rep & "Version.html", OpenMode.Input)
        While Not EOF(1)
            Ligne = LineInput(1)
            Pos = Ligne.IndexOf("Compte-voiturage Version")
            If Pos <> -1 Then
                VersionEnLigne = Ligne.Substring(Pos + 24).Trim
                Pos = VersionEnLigne.IndexOf(" ")
                If Pos <> -1 Then VersionEnLigne = VersionEnLigne.Substring(0, Pos)
            End If
        End While
        FileClose(1)
        If VersionEnLigne = "" Then
            MsgBox("Erreur lors de la récupération de la version actuelle de Compte-voiturage.", MsgBoxStyle.Exclamation)
        Else
            If VersionEnLigne > Application.ProductVersion Then
                If MsgBox("Il existe une version supérieur de Compte-voiturage sur le site officiel (V " & VersionEnLigne & ")" & vbCrLf & "Voulez-vous ouvrir la page du site pour la télécharger et la mettre à jour manuellement ?", vbYesNo + vbQuestion) = vbYes Then
                    System.Diagnostics.Process.Start("http://code.google.com/p/compte-voiturage/downloads/list")
                End If
            Else
                MsgBox("Votre version de Compte-voiturage est à jour", vbInformation)
            End If
        End If
    End Sub

    Private Sub AccéderAuSiteOfficielToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AccéderAuSiteOfficielToolStripMenuItem.Click

        System.Diagnostics.Process.Start("http://code.google.com/p/compte-voiturage")

    End Sub

End Class